<?php

/**
 * 消息异步回调通知表
 * @author chenshubo
 */
namespace App\Model\PssLogModel;

use App\Model\BaseModel\BasePssLogModel;
use App\Service\Code\Normal;

class MessageCallBackNotifyLog extends BasePssLogModel
{
    public $table = 'message_callback_notify_log';

    /**
     * 添加日志
     * @param array $param
     */
    public function addLog( $param = [] )
    {
        $rule = [
            "user_type"         => '业务类型',
            "event_sn"          => "业务编号",
            "message_type"      => '业务模块',
            "message"           => '消息body',
            "response_to_req"   => '业务响应格式',
            "client_ip"         => '客户端IP',
            "source"            => '写入来源'
        ];

        foreach ($rule as $key => $value ) {
            if( !array_key_exists($key,$param) ) {
                return Normal::returnCode(Normal::FAIL,"请求参数【{$key}】缺失");
            }
        }

        return $this->add([
            'user_type'         => $param['user_type'],
            'event_sn'          => $param['event_sn'],
            'message_type'      => $param['message_type'],
            'message'           => json_encode($param['message'],JSON_UNESCAPED_UNICODE),
            'source'            => $param['source'],
            'response_to_req'   => $param['response_to_req'],
            'request_ip'        => $param['client_ip'],
            'cd'                => time(),
        ]);
    }
}